package com.caesar.jdbc;

import com.caesar.bean.User;
import com.caesar.dao.BaseDao;
import org.junit.jupiter.api.Test;

import java.util.List;

/**
 * @author caesar
 * @date 2025/7/29
 * @Description:
 * @apiNote
 */
public class UserDao extends BaseDao {

    @Test
    public void testInsert() {
        String sql = "insert into t_user values(null,?,?,?,?,100)";
        int result = this.update(sql, "zhangsan", "123456", 23, "男");
        System.out.println("result = " + result);
    }

    @Test
    public void testSelectAll() {
        String sql = "select id,name username,password,age,gender from t_user";
        List<User> list = this.getBeanList(sql, User.class);
        list.forEach(System.out::println);
    }

    @Test
    public void testSelectOne() {
        String sql = "select id,name username,password,age,gender from t_user where id = ?";
        User user = this.getBean(sql, User.class, 1);
        System.out.println(user);
    }

    @Test
    public void testSelectCount() {
        String sql = "select count(1) from t_user";
        Long count = (Long) this.getSingleData(sql);
        System.out.println("count = " + count.intValue());
    }

}

